// 声明变量
let crypto;
// 判断当前nodejs是否支持crypto模块
try {
  crypto = require('node:crypto');
//   console.log(crypto);
} catch (err) {
  console.log('crypto support is disabled!');
}

// 加密前缀，给解密加点难度
const key = '#$@&$(*^)*%GGDFUIuu21432d@$EDD$%WRdf35qr12hufsfv';

// 加密
function aesEnc(data) {
  const cipher = crypto.createCipher('aes192', key);
  var crypted = cipher.update(data, 'utf8', 'hex');
  crypted += cipher.final('hex');
  return crypted;
}

// 解密
function aesDec(enc) {
  const decipher = crypto.createDecipher('aes192', key);
  var decrypted = decipher.update(enc, 'hex', 'utf8');
  decrypted += decipher.final('utf8');
  return decrypted;
}


// 暴露出去

module.exports = {
  aesEnc,
  aesDec
}




